/******************************************************************************
 * Author:      671643387
 * Created:     2016/9/27
 *****************************************************************************/

var fs = require('fs');
var HttpReq = require("../HttpRequest.js");
var BG      = require("../BackGroundID.js");
var util    = require("util");

exports.login = function(player, query, resp, onHandled) {
    var user = player.user;

    var name = query.args.name;
    var headpic = query.args.headpic;
    var sex = query.args.sex;

    user.info.name = name;
    user.info.headpic = headpic;
    user.info.sex = sex;
    var notice = "欢迎来到老麻子棋牌！";
    HttpReq.requestGameManage(BG.ReqArgs.NOTICE_API, player.uid, name, null, function (res) {
        if(res.reason.content) {
            notice = res.reason.content;
        }
        // 发送响应
        var tempdata = {
            info : {
                name : user.info.name,
                headpic : user.info.headpic,
                sex : sex,
            },
            status : {
                card : user.status.card,
            },
            marks : {
                room : user.marks.room,
            },
            reports : [],
            notice : notice,
        };

        player.sendMsg(0, "", "login", tempdata );
        onHandled();
    });
};

exports.getRecord = function(player, query, resp, onHandled) {
    var user = player.user;
    var code = 0;
    var desc = "";
    var date = user.reports;
    if(!date){
        code = 1;
        desc = " reports is null";
    }
    player.sendMsg(code, desc, "sendRecordMsg", {reports:date});
    onHandled();
};

exports.getPlayerInfo = function(player, query, resp, onHandled) {

    var user = player.user;
    var data = {
        name: user.info.name,
        headpic: user.info.headpic,
        uid: player.uid,
        totalGame: user.marks.totalgame,
        winGame:   user.marks.wingame,
    };
    var code = 0;
    var desc = "";
    if(!data){
        code = 1;
        desc = " PlayerInfo is null";
    }
    player.sendMsg(code, desc, "sendPlayerInfoMsg", data);
    onHandled();
};
